package 笔试记录.M10day21百度实习;

import java.util.HashMap;
import java.util.Map;

public class main2 {
    //[a a b c] abc a:2

    public static void main(String[] args) {
        char[] arr = {'a','c','b','a','a'};
        solve(arr);
    }

    public static void solve(char[] arr){
        HashMap<Character,Integer> hashMap = new HashMap<>();
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            if(hashMap.containsKey(arr[i])){
                hashMap.put(arr[i],hashMap.get(arr[i]) + 1);
            }else{
                str.append(arr[i]);
                hashMap.put(arr[i],1);
            }
        }
        System.out.println();
        String res = str.toString();
        char[] arr2 = res.toCharArray();
        for (int i = 0; i < arr2.length; i++) {
            System.out.print(arr2[i] + " ");
        }
        System.out.println();
        for(Map.Entry<Character,Integer> entry:hashMap.entrySet()){
            if(entry.getValue() != 1){
                System.out.println(entry.getKey()+":" + entry.getValue());
            }
        }
    }
}
